package com.littleken.foodiePojo.enums;

/*
 * Create by littleken on 2020/11/25 11:15
 */
public enum UserAddressDefaultEnum {

    NOT_DEFAULT(0,"非默认"),
    IS_DEFAULT(1,"默认"),
    ;
    private Integer code;
    private String desc;

    UserAddressDefaultEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    /**
     * 通过 CODE 获取 DESC
     * @param code
     * @return
     */
    public static String getDescByCode(Integer code) {
        for (UserAddressDefaultEnum addressEnum :UserAddressDefaultEnum.values()) {
            if (addressEnum.code.equals(code)) {
                return addressEnum.desc;
            }
        }
        return null;
    }

    /**
     * 通过 DESC 获取 CODE
     * @param desc
     * @return
     */
    public static Integer getCodeByDesc(String desc) {
        for (UserAddressDefaultEnum addressEnum : UserAddressDefaultEnum.values()) {
            if (addressEnum.desc.equals(desc)) {
                return addressEnum.code;
            }
        }
        return null;
    }

    /**
     * 通过 CODE 获取 Enum
     * @param code
     * @return
     */
    public static UserAddressDefaultEnum getEnumByCode(Integer code) {
        for (UserAddressDefaultEnum addressEnum :UserAddressDefaultEnum.values()) {
            if (addressEnum.code.equals(code)) {
                return addressEnum;
            }
        }
        return null;
    }
}
